import request from '@/utils/request';

/** 根据 id 获取算法 根据 id 获取算法 GET /api/algorithmInfo/get/vo */
export async function algorithmInfoGetVoUsingGet({ params, options }) {
  return request('/api/algorithmInfo/get/vo', {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

/** 分页获取算法列表 分页获取算法列表 POST /api/algorithmInfo/list/page/vo */
export async function algorithmInfoListPageVoUsingPost({ body, options }) {
  return request('/api/algorithmInfo/list/page/vo', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

/** 分页获取访客收藏的列表 分页获取访客收藏的列表 POST /api/algorithmInfo/my/collection/list/page/vo */
export async function algorithmInfoMyCollectionListPageVoUsingPost({
  body,
  options,
}) {
  return request('/api/algorithmInfo/my/collection/list/page/vo', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

/** 推荐算法 算法详情页推荐算法,根据 apply_scenarios 应用场景列表（json 数组）进行匹配 GET /api/algorithmInfo/recommend */
export async function algorithmInfoRecommendUsingGet({ params, options }) {
  return request('/api/algorithmInfo/recommend', {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

/** 获取算法试用结果 轮询获取算法试用结果 POST /api/algorithmInfo/result */
export async function algorithmInfoResultUsingPost({ body, options }) {
  return request('/api/algorithmInfo/result', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

/** 算法试用 根据算法id和上传的资源(image,video)对算法进行试用 POST /api/algorithmInfo/trial */
export async function algorithmInfoTrialUsingPost({
  params,
  body,
  file,
  options,
}) {
  const formData = new FormData();

  if (file) {
    formData.append('file', file);
  }

  Object.keys(body).forEach((ele) => {
    const item = body[ele];

    if (item !== undefined && item !== null) {
      formData.append(
        ele,
        typeof item === 'object' ? JSON.stringify(item) : item
      );
    }
  });

  return request('/api/algorithmInfo/trial', {
    method: 'POST',
    headers: {
      'Content-Type': 'multipart/form-data',
    },
    params: {
      ...params,
    },
    data: formData,
    ...(options || {}),
  });
}
